﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ModelPredictPro.General.IO {
    /// <summary>
    /// 此类为生成临时文件提供帮助
    /// </summary>
    public class TempFileInfo {
        public string FilePath { get; private set; }
        ~TempFileInfo() {
            Delete();
        }
        public TempFileInfo(IEnumerable<string> contents) {
            FilePath = FileHelper.GenerateRandomFilePath();
            if( contents != null )
                File.WriteAllLines(FilePath, contents.ToArray());
        }
        public TempFileInfo(string content) {
            FilePath = FileHelper.GenerateRandomFilePath();
            File.WriteAllText(FilePath, content);
        }

        public void Delete() {
            if (File.Exists(FilePath)) {
                File.Delete(FilePath);
            }
        }
    }
}
